// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html


const tool = require('ToolUtil');
// Date.prototype.format = function (format) {
//     var o = {
//         "M+": this.getMonth() + 1, //month
//         "d+": this.getDate(), //day
//         "h+": this.getHours(), //hour
//         "m+": this.getMinutes(), //minute
//         "s+": this.getSeconds(), //second
//         "q+": Math.floor((this.getMonth() + 3) / 3), //quarter
//         "S": this.getMilliseconds() //millisecond
//     };
//     if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
//         (this.getFullYear() + "").substr(4 - RegExp.$1.length));
//     for (var k in o)
//         if (new RegExp("(" + k + ")").test(format))
//             format = format.replace(RegExp.$1,
//                 RegExp.$1.length == 1 ? o[k] :
//                 ("00" + o[k]).substr(("" + o[k]).length));
//     return format;
// };

cc.Class({
    extends: cc.Component,

    properties: {
        btnContiune: cc.Button, //继续游戏
        btnEnter: cc.Button, //确定 直接进入大结算
        lbTime: cc.Label,
        lbName: cc.Label,
        lbTurn: cc.Label,
        balanceItem: {
            default: [],
            type: [cc.Node],
        },
        loadHander: cc.Component.EventHandler,
        _isGameOver: false, //是否已经全部结束

        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad: function () {
        if (this.balanceItem && this.balanceItem.length) {
            for (var i = 0; i < this.balanceItem.length; i++) {
                this.balanceItem[i].active = false;
            }
        }
    },

    start: function () {

    },

    gameOver: function (data, isRecord) {
        // this.lbTime.setString(new Date(data.time * 60000).formatTime());
        this.node.active = true;

        if (this.balanceItem && this.balanceItem.length) {
            for (var i = 0; i < this.balanceItem.length; i++) {
                this.balanceItem[i].active = false;
            }
        }
        if (this.loadHander && data.player) {
            for (var i = 0; i < data.player.length; i++) {
                var p = tool.PlayerManager().getPlayer(data.player[i].id, isRecord);
                this.balanceItem[i].active = true;
                this.loadHander.emit([this.balanceItem[i], p, i, data.player[i], data]);
            }
        }
    },

    //是否游戏已经结束
    setIsGameOver: function (isGameOver) {
        if (this.btnContiune == null || this.btnEnter == null) {
            return;
        }
        if (isGameOver) {

        } else {

        }
        // btnContiune: cc.Button, //继续游戏
        // btnEnter: cc.Button, //确定 直接进入大结算
    },

    onViewClick: function (sender, data) {
        switch (data) {
            case 'enter':

                break;
            case 'contuine':

                break;
            default:
                break;
        }
    }

    // update (dt) {},
});